package handlers

import (
	"2-11zy/api/request"
	"2-11zy/api/response"
	"2-11zy/dao"
	"2-11zy/models"
	"github.com/gin-gonic/gin"
)

func AddArticle(c *gin.Context) {
	var data request.Add
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	artice := models.Artice{
		Title:   data.Title,
		Author:  data.Author,
		Context: data.Context,
		Type:    data.Type,
	}
	err = dao.Create(artice)
	if err != nil {
		response.ResponseSuccess(c, "添加失败")
		return
	}
	response.ResponseSuccess(c, artice.ID)

}

func AddFollow(c *gin.Context) {
	UserId := c.GetUint("userId")
	var data request.AddFollow
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	follOW := models.FollOW{
		ArticeId:     data.ArticeId,
		FollowUserId: data.FollowUserId,
		UserId:       int(UserId),
	}
	err = dao.CreateFollow(follOW)
	if err != nil {
		response.ResponseError(c, "关注失败")
		return
	}
	response.ResponseSuccess(c, follOW.ID)

}
